<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>加盟商审核列表</title>
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/default/easyui.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/icon.css}">
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.easyui.min.js}"></script>
	<script type="text/javascript">
	   $(function(){
	       $('#examinelist').datagrid({  
      				title:'加盟商审核列表',  
      				iconCls:'icon-save',
                    queryParams:{
                       "name": null,
                       "flag": -1,
                       "type": 1
                    },
                    url:"/manager/examine/findAll",
      				columns:[
                          [
                					       {field:'title',title:'审核标题',width:200,align:'center'},
                                 {field:'name',title:'加盟商名称',width:200,align:'center'},
                                 {field:'address',title:'加盟商地址',width:200,align:'center',formatter:function(val,row){
                                         var link = "<a href='/manager/map/showMap?gps=" + row.gps + "' target='view_window'>" + val + "</a>";
                                         return link;
                                   }},   
                                 {field:'typeid',title:'服务类型',width:100,align:'center',formatter:function (val,row){
                                         return val === 1?"生活":"商务";
                                     }},
                                 {field:'createdate',title:'提交日期',width:100,align:'center',formatter:function (val,row){
                                         var createdate = new Date(val);
                                         var year = createdate.getFullYear();
                                         var month = ('' + (createdate.getMonth() + 1)).slice(-2);
                                         var day = ('' + createdate.getDate()).slice(-2);
                                         return year + '-' + month + '-' + day;
                                     }},
                                 {field:'username',title:'申请账户名',width:100,align:'center'},
                                 {field:'flag',title:'状态',width:100,align:'center',formatter(val,row){
                                         if(val === 2){
                                             return "待审核";
                                         }else if(val === 1){
                                             return "通过";
                                         }else if(val === 0){
                                             return "不通过"
                                         }else{
                                             return "-";
                                         }
                                     }},
                                 {field:'cz',title:'操作',width:200,align:'center',formatter:function(val,row){
                                       return "<a href='javascript:showDg();'>查看加盟商详情</a>";
                                 }}
                          ]
                    ],
      				toolbar: "#tooldiv",  
      				pagination: true,
      				singleSelect:true
			});


          
          //初始化修改窗口  
         $('#dg').dialog({
    			    title: '加盟商详情',
    			    width: 700,
    			    height: 700,
    			    closed: true,
    			    cache: false,
    			    modal: true,
    			    iconCls: 'icon-save'
    			});

         $("#examinedg").dialog({
              title: '审核操作',
              width: 500,
              height: 300,
              closed: true,
              cache: false,
              modal: true,
              iconCls: 'icon-save',
              buttons: [{
                    text:'提交',
                    iconCls:'icon-ok',
                    handler:function(){
                      if($('#examinedg textarea').val().trim() === ""){
                          alert("审核备注内容不能为空!")
                      }else{
                          var selectedRow = $('#examinelist').datagrid('getSelected');
                          var index = $("#examinelist").datagrid('getRowIndex', selectedRow);
                          $.ajax({
                              type: 'post',
                              dataType: "json",
                              url: "/manager/examine/examineCompany",
                              data: {
                                  "id": selectedRow.id,
                                  "flag": $('#examinedg #search_type').val(),
                                  "examineInfo": $('#examinedg textarea').val(),
                                  "managerUserId": sessionStorage.getItem("USER_ID")
                              },
                              success: function (result) {
                                  if (result.status == 200) {
                                      alert(result.msg);
                                      $("#examinelist").datagrid('updateRow', {
                                          index: index,
                                          row: {
                                              flag : parseInt($('#examinedg #search_type').val(), 10)
                                          }
                                      });
                                      $('#examinedg').dialog('close');
                                  }
                              },
                              error: function (xhr, status, error) {
                                  alert("请求失败: " + xhr.responseText); // 处理 AJAX 请求错误
                              }
                          });
                      }
                    }
                },{
                    text:'关闭',
                    handler:function(){
                        $('#examinedg').dialog("close");
                    }
                }]
          });

         //初始化查询按钮
         $("#submit_search").linkbutton({ iconCls: 'icon-search', plain: true })
            .click(function () {
                const tooldiv = document.getElementById('tooldiv');
                const inputs = tooldiv.querySelectorAll('input[type="text"]');
                const select = tooldiv.querySelectorAll('select');
                var pager = $('#examinelist').datagrid('getPager');
                // 直接设置数据网格的查询参数
                var queryParams = {
                    "page": 1,
                    "name": inputs[0].value,
                    "flag": select[0].value,
                    "type": 1
                };
                $('#examinelist').datagrid('options').queryParams = queryParams;
                $('#examinelist').datagrid('reload');
                pager.pagination('refresh', {
                    pageNumber: 1
                });
            });
            
	   });

        //查询弹出方法
       function showDg(){
           var selectedRow = $('#examinelist').datagrid('getSelected');
           $.ajax({
               dataType: "json",
               url: "/manager/examine/findServerCompany",
               data: {"id":selectedRow.id},
               success: function (result) {
                   if (result.status == 200) {
                       $('#dg').dialog("open");
                       var createdate = new Date(result.data.createdate);
                       var year = createdate.getFullYear();
                       var month = ('' + (createdate.getMonth() + 1)).slice(-2);
                       var day = ('' + createdate.getDate()).slice(-2);
                       var formattedDate = year + '-' + month + '-' + day;
                       $("#dg input.easyui-textbox:eq(0)").textbox("setValue", result.data.name);
                       $("#dg input.easyui-textbox:eq(1)").textbox("setValue", result.data.address);
                       $("#dg input.easyui-textbox:eq(2)").textbox("setValue", result.data.phone);
                       $("#dg input.easyui-textbox:eq(3)").textbox("setValue", result.data.linkman);
                       $("#dg input.easyui-textbox:eq(4)").textbox("setValue", result.data.scale);
                       $("#dg input.easyui-textbox:eq(5)").textbox("setValue", formattedDate);
                       $('#dg textarea').val(result.data.info);
                       $('#dg .imgtab').empty();
                       (result.data.imageUrls || []).forEach(function(imageUrl) {
                           var img = $('<img>').attr('src', imageUrl).attr('alt', '').css({
                               'width': '100px',
                               'height': '100px'
                           });
                           $('#dg .imgtab').append(img);
                       });
                   }
               },
               error: function (xhr, status, error) {
                   alert("请求失败: " + xhr.responseText); // 处理 AJAX 请求错误
               }
           });
       }

       //打开审核操作界面方法
       function openexaminedg(){
           var selectedRow = $('#examinelist').datagrid('getSelected');
           if(selectedRow){
               if(selectedRow.flag === 1 || selectedRow.flag === 0){
                   alert("只能审核状态为待审核的数据!")
               }else{
                   $("#examinedg").dialog("open");
                   $('#examinedg #search_type').val(1);
                   $('#examinedg textarea').val("");
               }
           }else{
               alert("请选中列表中对应的信息!")
           }
       }
	</script>
</head>
<body>
  <div id="tooldiv">
      <input type="text"  placeholder="请输入查询加盟商"/>
      <select>
          <option value="-1">请选状态</option>
          <option value="2">待审核</option>
          <option value="1">已通过</option>
          <option value="0">未通过</option>
      </select>
      <a id="submit_search">搜索</a>
      <a  class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="openexaminedg();">审核</a>
  </div>
  <table id="examinelist"></table>
  <!--审核详情界面-->
    <div id="dg">
          <div align="center" style="margin-top: 30px">
            <div style="margin-bottom:20px">
                <input class="easyui-textbox"  style="width:50%" data-options="label:'服务商名称:'" readonly="true" value="安普惠融资担保有限公司" />
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox"  style="width:50%" data-options="label:'公司地址:'" readonly="true" value="南京市鼓楼区xxxxxx"/>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox"  style="width:50%" data-options="label:'公司电话:'" readonly="true" value="123456123"/>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox"  style="width:50%;" data-options="label:'联系人:'" readonly="true" value="谢老板"/>
            </div> 
            <div style="margin-bottom:20px">
                <input class="easyui-textbox"  style="width:50%;" data-options="label:'规模:'" readonly="true" value="100人以上"/>
            </div> 
            <div style="margin-bottom:20px">
                <input class="easyui-textbox"  style="width:50%;" data-options="label:'注册时间:'" readonly="true" value="2021-1-1"/>
            </div> 
            <div style="margin-bottom:20px">
                <textarea cols="80" rows="5" readonly="true" style="border: 0px;">
 百姓网成立于2005年3月，是国内领先的分类信息生态服务商，是中国互联网轻资产模式的典范百姓网致力于创造以分类信息业务为平台、多条垂直业务线布局的生态圈为用户提供涵生活服务、招聘求职、房屋租售、二手车买卖、二手交易、教育培训、同城交友等一站式本地生活服务信息平台，同时为中小微商户建立全方位的精准营销解决方案。
                </textarea>
          </div>
          <div class="imgtab">
              <img src="./images/tx.jpg" alt="" style="width: 100px;height: 100px;">
              <img src="./images/tx.jpg" alt="" style="width: 100px;height: 100px;">
              <img src="./images/tx.jpg" alt="" style="width: 100px;height: 100px;">
              <img src="./images/tx.jpg" alt="" style="width: 100px;height: 100px;">
              <img src="./images/tx.jpg" alt="" style="width: 100px;height: 100px;">

          </div>
      </div>
   </div>
   <!--审核操作界面-->
   <div id="examinedg">
         <div align="center" style="margin-top: 30px">
            <form id="ff" method="post"> 
             <table>
          <tr>
           <td>
              审核状态:
           </td>
           <td>
            <select name="search_type" id="search_type" style="width:100px">
              <option value="1">通过</option>
              <option value="0">不通过</option>
            </select>
           </td>
        </tr>
        <tr style="vertical-align:top">
           <td>
              审核备注:
           </td>
           <td>
             <textarea rows="10" cols="30"></textarea>
           </td>
        </tr>
       </table>     
        </form>
      </div>
   </div>
</body>
</html>